<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加学员</title>
    <script src="js/jquery-3.6.0.min.js"></script>
    <script>
        $(function () {
            $('[name="sname"]').blur(function () {
                var sname = $(this).val();

                if (sname==null||sname==""){
                    $("#msg1").text("姓名不能为空").css("color","red");
                    return
                }
                $.ajax({
                    url:"student",
                    data:{"sname":sname,"method":"checkSname"},
                    type:"post",
                    dateType:"text",
                    success:function (data) {
                        if (data=="true"){
                            $("#msg1").text("该姓名已存在").css("color","red");
                        }else {
                            $("#msg1").text("√").css("color","green");
                        }

                    }
                })

            })

        })
    </script>
    <style>
        span{
            color: red;
            font-size: 12px;
        }
    </style>
</head>
<body>
<form id="login" action="student" method="POST" enctype="multipart/form-data">
    <table border="1px" cellpadding="10px" cellspacing="0" align="center" width="500px">
        <caption><h2>添加新学员</h2></caption>
        <tr>
            <td>姓名</td>
            <td>
                <input type="text" name="sname">
                <span id="msg1"></span>
                <!--
              隐藏域绑定要执行的方法名
              -->
                <input type="hidden" name="method" value="addStudent">
            </td>
        </tr>
        <tr>
            <td>性别</td>
            <td>
                <input type="radio" name="sex" value="男" checked>男
                <input type="radio" name="sex" value="女">女
            </td>
        </tr>
        <tr>
            <td>年龄</td>
            <td>
                <input type="text" name="age">
            </td>
        </tr>
        <tr>
            <td>学历</td>
           <td>
                <select name="degree">
                    <option value="0">==请选择==</option>
                    <option value="专科">专科</option>
                    <option value="本科">本科</option>
                    <option value="硕士">硕士</option>
                    <option value="博士">博士</option>
                </select>
            </td>
        </tr>
        <tr>
            <td>头像</td>
            <td>
                <input type="file" name="pic">
            </td>
        </tr>
        <tr>
            <td>备注</td>
            <td>
                <textarea name="mark" rows="4" cols="40"></textarea>
            </td>
        </tr>
        <tr align="center">
            <td colspan="2">
                <input type="submit" value="添加">
                <input type="reset"  value="取消">
            </td>
        </tr>
    </table>
</form>
</body>
</html>
